/**
 * Created with IntelliJ IDEA.
 * Description:异常
 * User: LXW
 * Date: 2022-01-25
 * Time: 19:37
 */
class UserException extends RuntimeException {
    public UserException(String name) {
        super(name);
    }
}
class PassWordException extends RuntimeException {
    public PassWordException(String name) {
        super(name);
    }
}
public class Test {
    private static final String userName = "admin";
    private static final String passWord = "1,2,3,4,5,6";
    public static void login(String userName,String passWord) throws UserException,PassWordException {
        if (!Test.userName.equals(userName)) {
            throw new UserException("用户名错误");
        }
        if (!Test.passWord.equals(passWord)) {
            throw new PassWordException("密码错误");
        }
    }
    public static void main(String[] args) {
        try {
            login("admin","1,2,3,4,5,6");
        } catch (UserException | PassWordException e) {
            e.printStackTrace();
        }


    }
    public static void main2(String[] args) {
        try {
            int[] array = {1,2,3,4,5};  // 可能出现异常的代码
        } catch (IndexOutOfBoundsException e) {
            e.printStackTrace();   // 打印异常
        }
    }
    // 数组下标越界异常
    public static void main1(String[] args) {
        int[] array = {1,2,3,4,5};
        System.out.println(array[8]);
    }
}
